package com.hs.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Article;
import com.hs.sfzy.entity.Heartknowledge;
import com.hs.sfzy.mapper.HeartknowledgeMapper;
import com.hs.sfzy.service.HeartknowledgeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: sfzyBackEnd
 * @BelongsPackage: com.hs.sfzy.service.impl
 * @ClassName HeartknowledgeServiceImpl
 * @Author: 陈千鱼不是鱼
 * @CreateTime: 2024-10-24  10:04
 * @Description: 心理知识serviceImpl
 * @Version: 1.0
 */
@Service
@RequiredArgsConstructor
public class HeartknowledgeServiceImpl implements HeartknowledgeService {

    private final HeartknowledgeMapper heartknowledgeMapper;

    @Override
    public PageInfo<Heartknowledge> page(Integer pageNum, Integer pageSize, String name) {

        PageHelper.startPage(pageNum,pageSize);
        List<Heartknowledge> list = heartknowledgeMapper.selectAll(name);
        PageInfo<Heartknowledge> pageInfo = new PageInfo<Heartknowledge>(list);
        return pageInfo;
    }

    @Override
    public void save(Heartknowledge heartknowledge) {
        int i = heartknowledgeMapper.save(heartknowledge);
        if (i == 0){
            throw new RuntimeException("添加失败");
        }
    }

    @Override
    public void deleteById(Integer id) {
        int i = heartknowledgeMapper.deleteById(id);
        if (i == 0){
            throw new RuntimeException("删除失败");
        }
    }

    @Override
    public void update(Heartknowledge heartknowledge) {
        int i = heartknowledgeMapper.update(heartknowledge);
        if (i == 0){
            throw new RuntimeException("更新失败");
        }
    }


}
